<?php

namespace app\models;

use Yii;
use app\models\SampleDeliver;

/**
 * This is the model class for table "sample_from".
 *
 * @property integer $pk_id
 * @property integer $pt_id
 * @property integer $tube_total
 * @property string $tube_time
 * @property string $tube_taker
 * @property string $tube_memo
 * @property integer $dna_total
 * @property string $dna_taker
 * @property string $dna_time
 * @property integer $rna_total
 * @property string $rna_taker
 * @property string $rna_time
 * @property integer $deliver_id
 * @property string $crt_name
 * @property string $crt_time
 */
class SampleFrom extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'sample_from';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['pt_id', 'tube_total', 'tube_time', 'tube_taker', 'dna_total', 'dna_taker', 'dna_time', 'rna_total', 'rna_taker', 'rna_time', 'deliver_id', 'crt_name', 'crt_time'], 'required'],
            [['pt_id', 'tube_total', 'dna_total', 'rna_total', 'deliver_id'], 'integer'],
            [['tube_time', 'dna_time', 'rna_time', 'crt_time'], 'safe'],
            [['tube_taker'], 'string', 'max' => 20],
            [['tube_memo'], 'string', 'max' => 255],
            [['dna_taker', 'rna_taker'], 'string', 'max' => 30],
            [['crt_name'], 'string', 'max' => 10]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'pk_id' => 'Pk ID',
            'pt_id' => '分子号',
            'tube_total' => '取样总管数',
            'tube_time' => '取样时间',
            'tube_taker' => '取样人',
            'tube_memo' => '备注',
            'dna_total' => '提取DNA管数',
            'dna_taker' => 'DNA提取人',
            'dna_time' => 'DNA提取时间',
            'rna_total' => '提取RNA管数',
            'rna_taker' => 'RNA提取人',
            'rna_time' => 'RNA提取时间',
            'deliver_id' => '送测序公司',
            'crt_name' => '创建人',
            'crt_time' => '创建时间',
        ];
    }

    public function defaultValue()
    {
        $this->tube_time = date("Y-m-d");
        $this->dna_time = date("Y-m-d");
        $this->rna_time = date("Y-m-d");
    }

    public function getDeliver()
    {
        return $this->hasMany(SampleDeliver::className(), ['pk_id' => 'deliver_id']);
    }
}
